extends Label
class_name TextShower

@export var text_path:String
@export var is_showing:bool
@export var next_text_line_action:String
var all_text:String
var show_text_lines:Array
var is_showing_line_num:int = 0


func _ready() -> void:
	var file = FileAccess.open(text_path, FileAccess.READ)
	all_text = file.get_as_text()
	show_text_lines = all_text.split("\n")
	if is_showing:
		show_next_text_line()

func _process(_delta: float) -> void:
	if is_showing:
		if Input.is_action_just_pressed(next_text_line_action):
			show_next_text_line()

func show_next_text_line():
		if is_showing_line_num != show_text_lines.size():
			text = show_text_lines[is_showing_line_num]
			is_showing_line_num += 1
